home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1996 / MacHack 1996.toast / Hacks / Hacks ’90 / Validate Text Entry / Readme < prev    next >
Encoding:
Text File  |  1990-06-15  |  3.1 KB  |  55 lines  |  [TEXT/MPS ]

  1. Validation of entry into Modal Dialogs
  2.  
  3.   I apologize for the fragmentary nature of this submission, but it is culled from some
  4. Fortran code I happened to have with me, and as I do not have the Language Systems
  5. Fortran compiler with me, and rewriting it in C was not something I had time to
  6. do, it is submitted as is. There are some INCLUDE files I do not have with me, but
  7. if there is serious interest in this hack, I will try to grind out a working demo
  8. later. I cannot submit the entire program in which this feature exists, as there
  9. is code in it which I did not write.
  10.  
  11.   The problem which this hack (and it is a hack, in every sense of the word) addresses
  12. is how to solicit free text input from users and provide validation during entry.
  13. The conditions this example covers are integers in a range, floating point in a range
  14. (including the scientific format), and charater strings within a range of number of
  15. characters. Also doable (but not done here) would be money, time, dates, etc.
  16.  
  17.   The approach is to attempt to reject an invalid key press when possible, i.e. if
  18. the addition of that character to the string makes the string no longer meet the
  19. SANE definition for representation of a floating point, don't add it to the string.
  20. If the character is a valid character, but causes the string to exceed the bounds of
  21. the specified format, add it to the string, but draw the string as greyed text and
  22. grey the default round rect so the user understands that the value needs to be fixed
  23. before proceeding. The user can see the validation criteria by pressing the option key.
  24.  
  25.   In order to do this, we need several components:
  26.   
  27.   1) NumValFilter, a ModalDialog filter proc which handles keyboard and mouse events
  28.   2) ctlDimItem, a userItem which handles greying the text within the specified
  29.      dialog item
  30.   3) A Frm# resource, which specifies the validation criteria and the item in which
  31.      to display the validation criteria. Note that due to the inability of Rez
  32.      to generate a floating point number in a civilized fashion, I build this resource
  33.      with the assembler. How embarrising for Apple...
  34.   4) A routine which sets up the ModalDialog call
  35.   
  36.   As in any hack, there are areas in which this code battles nobly against the
  37. operating system (and wins). Specifically, if the user selects several characters
  38. and then presses a key, we need to carefully evaluate what the result will be,
  39. lest we replace a valid number with a letter. Also, we need to clean up the field
  40. if there was a selection range and the user tabs or clicks out of the field, as
  41. the Dialog manager will try to redraw the field and ungrey the text.
  42.  
  43.   Since I wrote all this, I believe I know better ways to do what I am doing, and
  44. may well rewrite this in C++, but I submit it mainly as an experiment in the human
  45. interface which addresses a problem many of us face every day - how to avoid pissing
  46. off the user by beeping and putting up an alert after the fact.
  47.  
  48. Jeff E Mandel MD MS
  49. Asst Professor of Anesthesiology
  50. 1430 Tulane Ave
  51. Tulane University School of Medicine
  52. New Orleans, LA 70112
  53.  
  54. (504) 588 5903
  55. AS01MEF@VM.TCS.TULANE.EDU